//
//  MCHongBaoPersonCollectionViewCell.m
//  XDYL
//
//  Created by menhao on 2018/3/21.
//  Copyright © 2018年 TLYL01. All rights reserved.
//

#import "MCHongBaoPersonCollectionViewCell.h"


@implementation MCHongBaoPersonCollectionViewCell
- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {
        // 用约束来初始化控件:
        self.textLabel = [[UILabel alloc] init];
        self.textLabel.textAlignment =NSTextAlignmentCenter;
        [self.contentView addSubview:self.textLabel];
        self.textLabel.textColor = RGB(102, 102, 102);
        self.textLabel.font = [UIFont systemFontOfSize:MC_REALVALUE(12)];
        
        UIImageView *imagev = [[UIImageView alloc] init];
        [self.contentView addSubview:imagev];
        imagev.image = [UIImage imageNamed:@"ddd"];
        self.imageV = imagev;
        self.backgroundColor = RGB(249, 249, 249);
        
#pragma mark — 如果使用约束来布局,则无需在preferredLayoutAttributesFittingAttributes方法中去修改cell上的子控件l的frame
        [self.textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
            
            make.top.equalTo(self.contentView).with.offset(0);
            make.left.equalTo(self.contentView).with.offset(MC_REALVALUE(5));
            make.height.equalTo(@(MC_REALVALUE(30)));
            make.right.equalTo(self.contentView).with.offset(MC_REALVALUE( - 12));
        }];
        
        
        [self.imageV mas_makeConstraints:^(MASConstraintMaker *make) {
            make.centerY.equalTo(self.textLabel);
            make.left.equalTo(self.textLabel.mas_right).offset(MC_REALVALUE(5));
            make.width.equalTo(@(MC_REALVALUE(6)));
            make.height.equalTo(@(MC_REALVALUE(7)));
        }];
    }
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    
    
}
#pragma mark — 实现自适应文字宽度的关键步骤:item的layoutAttributes
//- (UICollectionViewLayoutAttributes *)preferredLayoutAttributesFittingAttributes:(UICollectionViewLayoutAttributes *)layoutAttributes{
//
//    UICollectionViewLayoutAttributes *attributes = [super preferredLayoutAttributesFittingAttributes:layoutAttributes];
//    CGRect rect = [self.textLabel.text boundingRectWithSize:CGSizeMake(CGFLOAT_MAX, itemHeight) options:NSStringDrawingTruncatesLastVisibleLine|   NSStringDrawingUsesFontLeading |NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName: [UIFont systemFontOfSize:14]} context:nil];
//    rect.size.width +=8;
//    rect.size.height+=8;
//    attributes.frame = rect;
//    return attributes;
//
//}
@end
